package com.md.youyouhui.utils;

import android.app.Dialog;
import android.content.Context;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.md.youyouhui.R;
import com.md.youyouhui.databinding.DialogAdapterMealCheckBinding;
import com.md.youyouhui.net.response.OrderDetailResponse;
import com.md.youyouhui.ui.adapter.DataBoundViewHolder;

import java.util.List;

/**
 * Created by AdministratorZJ
 * on 2019/4/29.
 */
public class MealMinuteCheckDialog extends Dialog {
    private Context context;
    private List<OrderDetailResponse.Plan> plan;
    private String title;

    public MealMinuteCheckDialog(Context context, List<OrderDetailResponse.Plan> plan, String title) {
        super(context);
        this.plan = plan;
        this.context = context;
        this.title = title;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_meal);
        TextView viewById = findViewById(R.id.title);
        viewById.setText(title);
        RecyclerView recyclerView = findViewById(R.id.dialogRecycler);
        recyclerView.setAdapter(new MyAdapter());
    }

    class MyAdapter extends RecyclerView.Adapter<DataBoundViewHolder<DialogAdapterMealCheckBinding>> {

        @NonNull
        @Override
        public DataBoundViewHolder<DialogAdapterMealCheckBinding> onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
            DialogAdapterMealCheckBinding mealBinding = DataBindingUtil.inflate(LayoutInflater.from(viewGroup.getContext()), R.layout.dialog_adapter_meal_check, viewGroup, false);
            return new DataBoundViewHolder<>(mealBinding);
        }

        @Override
        public void onBindViewHolder(@NonNull DataBoundViewHolder<DialogAdapterMealCheckBinding> holder, int i) {
            //0进行
            holder.binding.money.setText(plan.get(i).topUpAmount);
            holder.binding.num.setText(plan.get(i).serial);
            holder.binding.time.setText(plan.get(i).topUpTime);
            if (plan.get(i).state == 0) {
                holder.binding.check.setVisibility(View.GONE);
            } else {
                holder.binding.check.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public int getItemCount() {
            return null == plan ? 0 : plan.size();
        }
    }
}
